/**
 * Filename: PopListImageDir.java
 *
 * @author Firefly
 * @contact postfirefly@163.com
 * @time 2016/3/17 15:09
 */
package com.github.postsanf.yinian.activity.pop;

import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;

import com.amap.api.services.core.PoiItem;
import com.github.postsanf.yinian.R;
import com.github.postsanf.yinian.adapter.CommonAdapter;
import com.github.postsanf.yinian.utils.LocalViewHolder;

import java.util.List;

public class PopListPoiSearchNew extends BasePopupWindowForListView<PoiItem> {
    private ListView mListDir;
    private CommonAdapter adapter;

    public PopListPoiSearchNew(int width, int height,
                               List<PoiItem> datas, View convertView) {
        super(convertView, width, height, true, datas);
    }

    @Override
    public void initViews() {
        mListDir = (ListView) findViewById(R.id.lv_album_list_dir);
        adapter = new CommonAdapter<PoiItem>(context, mDatas,
                R.layout.map_location_item, 0) {
            @Override
            public void convert(LocalViewHolder helper, PoiItem item, Boolean isFirst) {
                helper.setText(R.id.location_item_tt, item.getTitle());
                helper.setText(R.id.location_item_des, item.getSnippet());
            }
        };
        mListDir.setAdapter(adapter);
    }

    public interface OnImageDirSelected {
        void selected(PoiItem floder);
    }

    private OnImageDirSelected mImageDirSelected;

    public void setOnImageDirSelected(OnImageDirSelected mImageDirSelected) {
        this.mImageDirSelected = mImageDirSelected;
    }

    public void setAdapterNotify() {
        adapter.notifyDataSetChanged();
    }

    @Override
    public void initEvents() {
        mListDir.setOnItemClickListener(new OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view,
                                    int position, long id) {
                if (mImageDirSelected != null) {
                    mImageDirSelected.selected(mDatas.get(position));
                }
            }
        });
    }

    @Override
    public void init() {
        // TODO Auto-generated method stub

    }

    @Override
    protected void beforeInitWeNeedSomeParams(Object... params) {
        // TODO Auto-generated method stub
    }

}
